#define _CRT_SECURE_NO_WARNINGS 
#include  <stdio.h>
#include <string.h>
#include <stdlib.h> 
// void print(int arr[], int sz)
//{
//	 int i = 0; 
//	 for (i = 0; i < sz; i++)
//	 {
//
//		 printf("%d ", arr[i]);
//	 }
//
//}
////int cmp_int(const void* p1, const void* p2)
////{
////	if (*(int*)p1 > *(int*)p2)
////		return 1;
////	else if (*(int*)p1 < *(int*)p2)
////		return -1;
////	else
////		return 0;
////
//// }
////void test()
////{
////
////	int arr[10] = { 1,4,3,2,5,8,6,7,9,10 };
////	int sz = sizeof(arr) / sizeof(arr[0]);
////	qsort(arr, sz, sizeof(arr[0]), cmp_int);
////	print(arr, sz);
////
//// }


struct stu
{

	char name[20];
	int age;
};

int cmp_my_name(const void* p1, const void* p2)
{
	return strcmp(((struct stu*)p1)->name, ((struct stu*)p2)->name);


}

void test1()
{
	struct stu arr[] = { {"chneyun ",32}, {"qiangge",45 } ,{"huazi",56} };
	int sz = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, sz, sizeof(arr[0]), cmp_my_name);

 }
int cmp_my_age(const void* p1, const* p2)
{
	return ((struct stu*)p1)->age - ((struct stu*)p2)->age;

 }
void test2()
{
	struct stu arr[] = { {"chneyun ",32}, {"qiangge",90 } ,{"huazi",56} };
	int sz = sizeof(arr) / sizeof(arr[0]); 
	qsort(arr, sz, sizeof(arr[0]), cmp_my_age );
 }

int cmp_int(const void* p1, const* p2)
{
	return (*(int *)p1) - (*(int *)p2);

}
void swap(char* buff1, char* buff2,int whith)
{
	int i = 0;
	char tmp = 0;
	for (i = 0; i < whith; i++)
	{
		tmp = *buff1;
		*buff1 = *buff2;
		*buff2 = tmp;
		buff1++;
		buff2++;
	}

 }
void bubble_sort(void* base, size_t sz, size_t whith, int (*cmp ) (const void* p1, const void* p2))
{
	int i = 0; 
	int j = 0; 
	for (i = 0; i <sz-1; i++)
	{
		for (j = 0; j < sz - 1 - i; j++)
		{
			if (cmp ( (char *)base + j*whith , (char * )base +(j +1)*whith )>0)
			{
				swap((char*)base + j * whith, (char*)base + (j + 1) * whith, whith);

			}

		}

	}
 }
void print(int arr[], int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)
	{

		printf("%d ", arr[i]);
	}

}
void test3()
{
	int arr[] = { 1,2,3,4,7,6,5,9,8,10 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	bubble_sort(arr, sz,sizeof(arr[0]),cmp_int );
		print(arr, sz);

}
int main()
{
	//test1();
	//test2();
	test3();

	return 0; 
}
   